<?php

require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

// 发布订阅模式
// 创建一个链接,指定用vhost为fanout
$arg = [
    'rabbitmq',
    'rabbitmq',
    'fanout',
];
$connection = new AMQPStreamConnection('localhost', 5672, ...$arg);
$channel    = $connection->channel();

$exchange_name = "hello_exchange";

// 声明队列
$channel->exchange_declare($exchange_name, 'fanout', false, false, false);
for($i=0;$i<10;$i++){
$msg = new AMQPMessage('Hello word'.$i);
$channel->basic_publish($msg, $exchange_name);
}

// 关闭连接
$channel->close();
$connection->close();
